﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Trading.Enquiry.SaleEnquiryChecklist;
using BCService.Trading.Enquiry.SaleEnquiryChecklist;
using BCService.Utils;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Management.Trading.Enquiry
{
    /// <summary>
    /// 销售询盘清单
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class SaleEnquiryChecklistController : ManagementBaseController
    {
        private readonly ISaleEnquiryChecklistService saleEnquiryChecklistService;

        public SaleEnquiryChecklistController(ISaleEnquiryChecklistService saleEnquiryChecklistService)
        {
            this.saleEnquiryChecklistService = saleEnquiryChecklistService;
        }

        #region 添加销售询盘清单
        /// <summary>
        ///  添加销售询盘清单
        /// </summary>
        /// <param name="requestDto">销售询盘清单信息</param>
        /// <response code="201">添加销售询盘清单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加销售询盘清单")]
        [ProducesResponseType(typeof(SaleEnquiryChecklistDto), 201)]
        public IActionResult Post(
            [FromBody]SaleEnquiryChecklistRequestDto requestDto)
        {
            var result = this.saleEnquiryChecklistService.Add(requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改销售询盘清单
        /// <summary>
        ///  修改销售询盘清单
        /// </summary>
        /// <param name="saleEnquiryChecklistId">销售询盘清单Id</param>
        /// <param name="putDto">销售询盘清单信息</param>
        /// <response code="200">修改销售询盘清单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{sale_enquiry_checklist_id}")]
        [Log("修改销售询盘清单")]
        [ProducesResponseType(typeof(SaleEnquiryChecklistDto), 200)]
        public IActionResult Put([FromRoute(Name = "sale_enquiry_checklist_id")]long saleEnquiryChecklistId, [FromBody]SaleEnquiryChecklistPutDto putDto)
        {
            putDto.SaleEnquiryChecklistId = saleEnquiryChecklistId;
            return StatusCode((int)HttpStatusCode.OK, this.saleEnquiryChecklistService.Update(putDto));
        }
        #endregion

        #region 删除销售询盘清单
        /// <summary>
        ///  删除销售询盘清单
        /// </summary>
        /// <param name="saleEnquiryChecklistId">销售询盘清单Id</param>
        /// <response code="204">删除销售询盘清单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{sale_enquiry_checklist_id}")]
        [Log("删除销售询盘清单")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "sale_enquiry_checklist_id")]long saleEnquiryChecklistId)
        {
            this.saleEnquiryChecklistService.Delete(saleEnquiryChecklistId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取销售询盘清单
        /// <summary>
        ///  获取销售询盘清单
        /// </summary>
        /// <param name="saleEnquiryChecklistId">销售询盘清单Id</param>
        /// <response code="200">获取销售询盘清单</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{sale_enquiry_checklist_id}")]
        [ProducesResponseType(typeof(SaleEnquiryChecklistDto), 200)]
        public IActionResult Get([FromRoute(Name = "sale_enquiry_checklist_id")]long saleEnquiryChecklistId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleEnquiryChecklistService.Get(saleEnquiryChecklistId));
        }
        #endregion

        #region 获取销售询盘清单列表
        /// <summary>
        ///  获取销售询盘清单列表
        /// </summary>
        /// <param name="saleEnquiryId">销售询盘单Id</param>
        /// <response code="200">获取销售询盘清单列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{sale_enquiry_id}")]
        [ProducesResponseType(typeof(IEnumerable<SaleEnquiryChecklistDto>), 200)]
        public IActionResult List([FromRoute(Name ="sale_enquiry_id")]long saleEnquiryId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleEnquiryChecklistService.GetList(saleEnquiryId));
        }
        #endregion

        #region 获取销售询盘清单（分页）
        /// <summary>
        ///  获取销售询盘清单（分页）
        /// </summary>
        /// <param name="saleEnquiryId">销售询盘单Id</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取销售询盘清单（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<SaleEnquiryChecklistDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "sale_enquiry_id")]long? saleEnquiryId,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleEnquiryChecklistService.Query(saleEnquiryId, start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}
